{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/image-smoother\n",
    "\n",
    "\n",
    "\n",
    "Runtime: 1108 ms, faster than 5.17% of Python3 online submissions for Image Smoother.\n",
    "Memory Usage: 15 MB, less than 6.35% of Python3 online submissions for Image Smoother.\n",
    "\n",
    "\n",
    "\n",
    "```python\n",
    "import math\n",
    "\n",
    "class Solution:\n",
    "    width = 0\n",
    "    height = 0\n",
    "    M = None\n",
    "    \n",
    "    def valid(self, point):\n",
    "        x,y = point\n",
    "        if x >= 0 and x <= self.width-1:\n",
    "            if y >=0 and y <= self.height-1:\n",
    "                return True\n",
    "        return False\n",
    "        \n",
    "    def average(self, x, y):\n",
    "        points = [\n",
    "            (x-1, y-1),\n",
    "            (x, y-1),\n",
    "            (x+1, y-1),\n",
    "            (x-1, y),\n",
    "            (x, y),\n",
    "            (x+1, y),\n",
    "            (x-1, y+1),\n",
    "            (x, y+1),\n",
    "            (x+1, y+1)\n",
    "        ]\n",
    "        l = []\n",
    "        for point in points:\n",
    "            if self.valid(point):\n",
    "                x0, y0 = point\n",
    "                l.append(self.M[y0][x0])\n",
    "        return math.floor(sum(l)/len(l))\n",
    "        \n",
    "    def imageSmoother(self, M: List[List[int]]) -> List[List[int]]:\n",
    "        self.height = len(M)\n",
    "        self.width = len(M[0])\n",
    "        self.M = M\n",
    "        newM = [ [ 0 for i in range(self.width) ] for j in range(self.height) ]\n",
    "        for y in range(self.height):\n",
    "            for x in range(self.width):\n",
    "                val = self.average(x, y)\n",
    "                newM[y][x] = val\n",
    "        return newM\n",
    "```\n",
    "\n",
    "spent 16 minutes\n",
    "\n",
    "tried 1 time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
